using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace Mod.EverlastingLogin {
    public class Migrations : DataMigrationImpl {

        public int Create() {
			// Creating table CookieSettingsPartRecord
			SchemaBuilder.CreateTable("CookieSettingsPartRecord", table => table
				.ContentPartRecord()
				.Column("Days", DbType.Int32)
				.Column("Hours", DbType.Int32)
				.Column("Minutes", DbType.Int32)
				.Column("Seconds", DbType.Int32)
				.Column("Milliseconds", DbType.Int32)
				.Column("UseCookies", DbType.Boolean)
			);

            return 1;
        }

        public int UpdateFrom1()
        {
            ContentDefinitionManager.AlterTypeDefinition("CookiePopupWidget", e => e
                .WithPart("BodyPart")
                .WithSetting("Stereotype", "Widget"));

            return 2;
        }

        public int UpdateFrom2()
        {
            ContentDefinitionManager.AlterTypeDefinition("CookiePopupWidget", e => e.WithPart("WidgetPart"));

            return 3;
        }

        public int UpdateFrom3()
        {
            ContentDefinitionManager.AlterTypeDefinition("CookiePopupWidget", e => e.WithPart("CommonPart"));
            ContentDefinitionManager.AlterTypeDefinition("CookiePopupWidget", e => e.WithPart("IdentityPart"));

            return 4;
        }
    }
}